#ifndef CCOLORPICKER_H
#define CCOLORPICKER_H

#include "afxdef.h"
#include <QWidget>
#include <QMouseEvent>
#include <QPixmap>
#include <QVector>
#include <QColor>

class CColorPicker : public QWidget
{
    Q_OBJECT
public:
    explicit CColorPicker(QWidget *parent = nullptr);
    QColor getColor();

   void Move(const QPoint& pos, PosQuadrant quadrant = PosQuadrant::rightBottom);

    void SetScreenCapture(const QPixmap &pixmap);
signals:
    void colorSelected(const QColor &color);

protected:
    void paintEvent(QPaintEvent *event) override;

private:
    void captureScreen();
    void drawMagnifier(QPainter &painter);
    void drawColorInfo(QPainter &painter);
    void drawHistory(QPainter &painter);
    void addToHistory(const QColor &color);

    QPixmap m_screenCapture;
    QImage m_screenCaptureImage;
    QPoint m_cursorPos;
    QColor m_currentColor;
    QVector<QColor> m_colorHistory;

    // 配置参数
    const int MAGNIFIER_SIZE = 160;
    const int COLORINFO_HEIGHT = 50;
    const int MAGNIFICATION = 8;
    const int HISTORY_SIZE = 8;
};

#endif // CCOLORPICKER_H
